package cn.cvs.service;

import cn.cvs.dao.SysRoleMapper;
import cn.cvs.pojo.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Transactional
@Service("SysRoleService")
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public List<SysRole> getRoleList() throws Exception {

        return this.sysRoleMapper.selectList();
    }

    @Override
    public int  add(SysRole sysRole) throws Exception {
        return this.sysRoleMapper.add(sysRole);
    }

    @Override
    public int  deleteById(Integer id) throws Exception {
        return this.sysRoleMapper.deleteById(id);
    }

    @Override
    public boolean update(SysRole sysRole) throws Exception {
        boolean flag = false;
        sysRole.setUpdatedTime(new Date());
        if (this.sysRoleMapper.update(sysRole) > 0) {
            flag = true;
        }
        return flag;
    }

    @Override
    public SysRole getById(Integer id) throws Exception {
        return this.sysRoleMapper.selectById(id);
    }

    @Override
    public int getCountByCode(String code) throws Exception {
        return this.sysRoleMapper.selectByCode(code);
    }
}
